//
//  APAvatarControl.m
//  AqualPolo
//
//  Created by dong on 2024/5/10.
//

#import "APAvatarControl.h"

@implementation APAvatarControl

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _avatarImageView = [[UIImageView alloc]init];
        _avatarImageView.layer.cornerRadius = 14;
        _avatarImageView.layer.masksToBounds = true;
        _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_avatarImageView];
        [_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(28, 28));
        }];
        
        _followButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
        [_followButton setBackgroundImage:[UIImage imageNamed:@"follow_icon"] forState:UIControlStateNormal];
        [_followButton addTarget:self action:@selector(followButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_followButton];
        [_followButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_avatarImageView);
            make.right.equalTo(_avatarImageView).offset(4);
            make.bottom.right.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(14, 14));
        }];
    }
    return self;
}


- (void)followButtonDidClick:(UIButton *)sender{
    sender.hidden = true;
    if (self.followClickHandler) {
        self.followClickHandler();
    }
}
@end
